package com.hermit.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hermit.system.dao.LoginDao;
import com.hermit.system.entity.UserInfoEntity;
import com.hermit.system.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("loginService")
public class LoginServiceImpl extends ServiceImpl<LoginDao, UserInfoEntity> implements LoginService {
    private final Logger logger = LoggerFactory.getLogger(getClass());


    @Autowired
    private LoginDao loginDao;

    /**
     * 登录
     */
    public UserInfoEntity login(Map<String, Object> params) {
        QueryWrapper<UserInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", params.get("username"));
        queryWrapper.eq("password", params.get("password"));
        queryWrapper.eq("delete_flag", 0);
        List<UserInfoEntity> userInfoEntities = loginDao.query(queryWrapper);
        if (userInfoEntities == null || userInfoEntities.size() != 1) {
            // 登录失败
            UserInfoEntity userInfoEntity = new UserInfoEntity();
            return userInfoEntity;
        }
        System.out.println("登录成功:" + userInfoEntities.get(0));
        return userInfoEntities.get(0);
    }

}
